//
// Created by glt on 2025/10/16.
//

#include <iostream>
#include "addressbook.pb.h"

int main() {
    tutorial::AddressBook book;

    // 添加一个人
    auto* person = book.add_people();
    person->set_name("Alice");
    person->set_id(123);
    person->set_email("alice@example.com");

    auto* phone = person->add_phones();
    phone->set_number("555-1234");
    phone->set_type(tutorial::Person::MOBILE);

    // 序列化
    std::string data;
    if (!book.SerializeToString(&data)) {
        std::cerr << "序列化失败\n";
        return 1;
    }
    std::cout << "序列化成功，字节长度: " << data.size() << "\n";

    // 反序列化
    tutorial::AddressBook book2;
    if (!book2.ParseFromString(data)) {
        std::cerr << "反序列化失败\n";
        return 1;
    }

    std::cout << "反序列化成功！人数: " << book2.people_size() << "\n";
    return 0;
}